
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllPigstys", query = "select myPigsty from Pigsty myPigsty"),
		@NamedQuery(name = "findPigstyByCapacity", query = "select myPigsty from Pigsty myPigsty where myPigsty.capacity = ?1"),
		@NamedQuery(name = "findPigstyById", query = "select myPigsty from Pigsty myPigsty where myPigsty.id = ?1"),
		@NamedQuery(name = "findPigstyByMemo", query = "select myPigsty from Pigsty myPigsty where myPigsty.memo = ?1"),
		@NamedQuery(name = "findPigstyByMemoContaining", query = "select myPigsty from Pigsty myPigsty where myPigsty.memo like ?1"),
		@NamedQuery(name = "findPigstyByNumber", query = "select myPigsty from Pigsty myPigsty where myPigsty.number = ?1"),
		@NamedQuery(name = "findPigstyByPrimaryKey", query = "select myPigsty from Pigsty myPigsty where myPigsty.id = ?1"),
		@NamedQuery(name = "findPigstyByRfid", query = "select myPigsty from Pigsty myPigsty where myPigsty.rfid = ?1"),
		@NamedQuery(name = "findPigstyByRfidContaining", query = "select myPigsty from Pigsty myPigsty where myPigsty.rfid like ?1") })

@Table(catalog = "pig", name = "pigsty")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "Pigsty")
@XmlRootElement(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain")
public class Pigsty implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "Number", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Integer number;
	/**
	 */

	@Column(name = "RFID", length = 20, nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String rfid;
	/**
	 */

	@Column(name = "Capacity")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Integer capacity;
	/**
	 */

	@Column(name = "Memo")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String memo;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PigHouseId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	PigHouse pigHouse;
	/**
	 */
	@OneToMany(mappedBy = "pigsty", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Feed> feeds;
	/**
	 */
	@OneToMany(mappedBy = "pigsty", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Transfer> transfers;
	/**
	 */
	@OneToMany(mappedBy = "pigsty", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.Prevention> preventions;
	/**
	 */
	@OneToMany(mappedBy = "pigsty", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.InspectionException> inspectionExceptions;
	/**
	 */
	@OneToMany(mappedBy = "pigsty", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)

	
	java.util.Set<cn.edu.scau.cmi.hombio.domain.TaskPigsty> taskPigsties;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setNumber(Integer number) {
		this.number = number;
	}

	/**
	 */
	public Integer getNumber() {
		return this.number;
	}

	/**
	 */
	public void setRfid(String rfid) {
		this.rfid = rfid;
	}

	/**
	 */
	public String getRfid() {
		return this.rfid;
	}

	/**
	 */
	public void setCapacity(Integer capacity) {
		this.capacity = capacity;
	}

	/**
	 */
	public Integer getCapacity() {
		return this.capacity;
	}

	/**
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 */
	public String getMemo() {
		return this.memo;
	}

	/**
	 */
	public void setPigHouse(PigHouse pigHouse) {
		this.pigHouse = pigHouse;
	}

	/**
	 */
	@JsonIgnore
	public PigHouse getPigHouse() {
		return pigHouse;
	}

	/**
	 */
	public void setFeeds(Set<Feed> feeds) {
		this.feeds = feeds;
	}

	/**
	 */
	@JsonIgnore
	public Set<Feed> getFeeds() {
		if (feeds == null) {
			feeds = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Feed>();
		}
		return feeds;
	}

	/**
	 */
	public void setTransfers(Set<Transfer> transfers) {
		this.transfers = transfers;
	}

	/**
	 */
	@JsonIgnore
	public Set<Transfer> getTransfers() {
		if (transfers == null) {
			transfers = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Transfer>();
		}
		return transfers;
	}

	/**
	 */
	public void setPreventions(Set<Prevention> preventions) {
		this.preventions = preventions;
	}

	/**
	 */
	@JsonIgnore
	public Set<Prevention> getPreventions() {
		if (preventions == null) {
			preventions = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Prevention>();
		}
		return preventions;
	}

	/**
	 */
	public void setInspectionExceptions(Set<InspectionException> inspectionExceptions) {
		this.inspectionExceptions = inspectionExceptions;
	}

	/**
	 */
	@JsonIgnore
	public Set<InspectionException> getInspectionExceptions() {
		if (inspectionExceptions == null) {
			inspectionExceptions = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.InspectionException>();
		}
		return inspectionExceptions;
	}

	/**
	 */
	public void setTaskPigsties(Set<TaskPigsty> taskPigsties) {
		this.taskPigsties = taskPigsties;
	}

	/**
	 */
	@JsonIgnore
	public Set<TaskPigsty> getTaskPigsties() {
		if (taskPigsties == null) {
			taskPigsties = new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.TaskPigsty>();
		}
		return taskPigsties;
	}

	/**
	 */
	public Pigsty() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Pigsty that) {
		setId(that.getId());
		setNumber(that.getNumber());
		setRfid(that.getRfid());
		setCapacity(that.getCapacity());
		setMemo(that.getMemo());
		setPigHouse(that.getPigHouse());
		setFeeds(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Feed>(that.getFeeds()));
		setTransfers(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Transfer>(that.getTransfers()));
		setPreventions(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.Prevention>(that.getPreventions()));
		setInspectionExceptions(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.InspectionException>(that.getInspectionExceptions()));
		setTaskPigsties(new java.util.LinkedHashSet<cn.edu.scau.cmi.hombio.domain.TaskPigsty>(that.getTaskPigsties()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("number=[").append(number).append("] ");
		buffer.append("rfid=[").append(rfid).append("] ");
		buffer.append("capacity=[").append(capacity).append("] ");
		buffer.append("memo=[").append(memo).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Pigsty))
			return false;
		Pigsty equalCheck = (Pigsty) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
